@echo off

goto main

:main
    echo.
    echo  选择要执行的命令(输出数字即可):
    echo     1 安装(安装位置为当前文件夹)
    echo     0 卸载
    echo.
    set /p "mod=请输入："

    if %mod%==1 (
        goto install
    ) else if %mod%==0 (
        goto uninstall
    ) else (
        echo.
        echo 未知命令
        goto close
    )

REM 安装
:install
    echo 开始安装...
    set "out_path=.\__tmp_install_right.reg"
    setlocal enabledelayedexpansion

    set "exe_path=%~dp0PlistDumper.exe"
    set "escaped_exe_path=!exe_path:\=\\!"

    (
        echo Windows Registry Editor Version 5.00
        echo.
        echo [HKEY_CLASSES_ROOT\SystemFileAssociations\.plist\shell\PlistDumper]
        echo @="<-解包->"
        echo.
        echo [HKEY_CLASSES_ROOT\SystemFileAssociations\.plist\shell\PlistDumper\command]
        echo @="\"!escaped_exe_path!\" \"%%1\""
        echo.
        echo [HKEY_CLASSES_ROOT\SystemFileAssociations\.json\shell\PlistDumper]
        echo @="<-解包->"
        echo.
        echo [HKEY_CLASSES_ROOT\SystemFileAssociations\.json\shell\PlistDumper\command]
        echo @="\"!escaped_exe_path!\" \"%%1\""
        echo.
        echo [HKEY_CLASSES_ROOT\SystemFileAssociations\.fnt\shell\PlistDumper]
        echo @="<-解包->"
        echo.
        echo [HKEY_CLASSES_ROOT\SystemFileAssociations\.fnt\shell\PlistDumper\command]
        echo @="\"!escaped_exe_path!\" \"%%1\""
        echo.
        echo [HKEY_CLASSES_ROOT\Directory\shell\PlistDumperFolder]
        echo @="<-解包文件夹所有图集->"
        echo.
        echo [HKEY_CLASSES_ROOT\Directory\shell\PlistDumperFolder\command]
        echo @="\"!escaped_exe_path!\" \"%%1\""
    ) > %out_path%

    %out_path%
    del /f /q %out_path%
    endlocal
    goto end

REM 卸载
:uninstall
    echo 开始卸载...
    set "out_path=.\__tmp_uninstall_right.reg"
    echo Windows Registry Editor Version 5.00> %out_path%
    echo.>> %out_path%
    echo [-HKEY_CLASSES_ROOT\SystemFileAssociations\.plist\shell\PlistDumper]>> %out_path%
    echo.>> %out_path%
    echo [-HKEY_CLASSES_ROOT\SystemFileAssociations\.json\shell\PlistDumper]>> %out_path%
    echo.>> %out_path%
    echo [-HKEY_CLASSES_ROOT\SystemFileAssociations\.fnt\shell\PlistDumper]>> %out_path%
    echo.>> %out_path%
    echo [-HKEY_CLASSES_ROOT\Directory\shell\PlistDumperFolder]>> %out_path%

    %out_path%
    del /f /q %out_path%
    goto end

:end
    echo 执行完毕，任意键关闭。
    pause > nul
    goto over

:close
    echo 即将关闭。。。
    ping 127.0.0.1 > nul

:over